{{--/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/3/2 8:33
 * Desc:
 */--}}
@extends("layout.admin")

@section("title")
    系统设置
@endsection

@section("content")
    <style>
        .input-width {
            width: 32%;
        }
    </style>
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this"><a href="{{route('admin.set.index')}}">基础设置</a></li>
            <li><a href="{{route('admin.set.index.attach.1')}}">顶部导航</a></li>
            <li><a href="{{route('admin.set.index.attach.2')}}">用户设置</a></li>
            <li><a href="{{route('admin.set.index.attach.3')}}">微信设置</a></li>
            <li><a href="{{route('admin.set.index.attach.4')}}">企业微信设置</a></li>
            <li><a href="{{route('admin.set.index.attach.5')}}">钉钉设置</a></li>
            <li>云存储(暂缓)</li>
        </ul>
        <div class="layui-tab-content" style="height: auto;">
            {{--基础设置--}}
            <div class="layui-tab-item layui-show">
                <form class="layui-form" method="post">
                    {{csrf_field()}}
                    <div class="layui-form-item">
                        <label class="layui-form-label">网站名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" name="name" lay-verify="required" autocomplete="off"
                                   placeholder="请输入网站名称" class="layui-input input-width"
                                   @if($error==0) value="{{$set["value"]["name"]}}" @elseif($error>0) value="" @endif>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">网站LOGO</label>
                        <div class="layui-upload-drag" id="logo">
                            <i class="layui-icon"></i>
                            <p>点击上传，或将文件拖拽到此处</p>
                            <div @if($error>0) class="layui-hide" @endif id="uploadLogo">
                                <hr>
                                <img alt="上传成功后渲染" style="max-width: 62px"
                                     @if($error==0)
                                     @if($set["value"]['logo']) src="{{asset($set["value"]['logo'])}}"
                                    @endif
                                @elseif($error>0)
                                    @endif>
                            </div>
                            <input style="display: none;" @if($error==0) value="{{$set["value"]["logo"]}}"
                                   @else value="" @endif id="logoicon" name="logo">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">浏览器图标</label>
                        <img class="layui-upload-img" id="webicon" style="max-width: 62px;"
                             @if($error==0)
                             @if($set["value"]['webicon']) src="{{asset($set["value"]['webicon'])}}"
                             @else src="{{asset('images/temp.ico')}}"
                            @endif
                            @endif>
                        <button type="button" class="layui-btn layui-btn-danger" id="favicon"><i
                                class="layui-icon"></i>上传图片
                        </button>
                        <div class="layui-inline layui-word-aux">
                            上传扩展名为ico的图片(大小60kb)
                        </div>
                        <input style="display: none;" @if($error==0) value="{{$set["value"]["webicon"]}}"
                               @endif id="wicon" name="webicon">
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" id="site" data-name="site" class="layui-btn" lay-submit="">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection

@section("script")
    <script>
        layui.use(['element', 'form', 'upload'], function () {
            var $ = layui.jquery
                , upload = layui.upload;

            //上传网站logo
            upload.render({
                elem: '#logo'
                , url: "{{route('upload')}}"
                , method: "POST"
                , data: {"_token": "{{csrf_token()}}", "path": "logo"}
                , field: "img"
                , done: function (res) {
                    if (res.error == 0) {
                        layer.msg('上传成功');
                        layui.$('#uploadLogo').removeClass('layui-hide').find('img').attr('src', "/" + res.path);
                        $("#logoicon").val(res.path);
                        return false;
                    }
                    layer.msg('上传失败');


                }
            });

            //上传浏览器小图标
            upload.render({
                elem: '#favicon'
                , url: "{{route('upload')}}"
                , method: "POST"
                , data: {"_token": "{{csrf_token()}}", "path": "webicon"}
                , field: "img"
                , size: 60 //限制文件大小，单位 KB
                , done: function (res) {
                    if (res.error == 0) {
                        layer.msg('上传成功');
                        layui.$('#webicon').attr('src', "/" + res.path);
                        $("#wicon").val(res.path);
                        return false;
                    }
                    layer.msg('上传失败');
                }
            });

            $("#site").click(function (data) {
                let name = data.currentTarget.dataset.name;
                let value = {"name": $("#name").val(), "logo": $("#logoicon").val(), "webicon": $("#wicon").val()};
                admin.set("{{route('admin.set.create')}}","{{csrf_token()}}",name, value);
            });
        });
    </script>
@endsection

